package com.dna.okangjang.commons.servlet;

import java.util.Iterator;
import java.util.Set;

import javax.servlet.ServletException;

import org.springframework.web.context.WebApplicationContext;
import org.springframework.web.context.support.WebApplicationContextUtils;

import freemarker.template.Configuration;

@SuppressWarnings("serial")
public class FreemarkerDecoratorServlet extends
		com.opensymphony.module.sitemesh.freemarker.FreemarkerDecoratorServlet {

	@SuppressWarnings("unchecked")
	@Override
	public void init() throws ServletException {
		super.init();
		
		WebApplicationContext context = WebApplicationContextUtils.getRequiredWebApplicationContext(getServletContext());
		Configuration configuration = (Configuration)context.getBean("freemarkerConfiguration");
		
		Set keys = configuration.getSharedVariableNames();
		for(Iterator<String> it = keys.iterator(); it.hasNext();) {
			String name = it.next();
			getConfiguration().setSharedVariable(name, configuration.getSharedVariable(name));
		}
				
	}
}
